package com.hg.miaosha.product;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: skh
 * @Date: 2019/10/16 15:12
 * @Description:
 */
@Service
public class ProductService {

    @Autowired
    private ProductDao productDao;

    public ProductDO getProductByProductId(Integer productId) {
        ProductDO productDO = productDao.getProductByProductId(productId);
        return productDO;
    }

    public Integer reduceStock(Integer productId, Integer amount) {
        return productDao.reduceStock(productId,amount);
    }

    public List<ProductDO> getProductList() {
        List<ProductDO> productDOS = productDao.selectList(null);
        return productDOS;

    }

    @Transactional
    public void insertProduct() {
        ProductDO productDO = new ProductDO();
        productDO.setProductId(999);
        productDO.setName("测试分布式事务");
        productDO.setStock(999);
        productDao.insert(productDO);
        System.out.println("新增商品成功");

    }
}
